package cn.kpi.service.civilass.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import cn.kpi.dao.civilass.CivilAssTempDao;
import cn.kpi.entity.civilass.CATempDetailEntity;
import cn.kpi.entity.civilass.CivilAssTempEntity;
import cn.kpi.service.civilass.ICivilAssTempService;

@Service
public class CivilAssTempServiceImpl implements ICivilAssTempService{
	
	@Autowired
	private CivilAssTempDao civilAssTempDao;
	
	@Transactional
	public int InsertCivilAssTemp(CivilAssTempEntity entity,String itemids,List<Long> lstorg,String orgids)throws Exception{
		try{
			int result=0;
			result+=civilAssTempDao.UpdateCATempStatus();
			result+=civilAssTempDao.InsertCATemp(entity);
			Long tempid=entity.getCatempid();
			
			//result+=civilAssTempDao.InsertCATempDetailBatch(tempid, lstitem);
			result+=civilAssTempDao.UpdateCATempDetailStatus();
			result+=civilAssTempDao.InsertCATempDetailBatchOther(tempid, itemids);
			result+=civilAssTempDao.UpdateCATempOrgStatus(orgids);
			result+=civilAssTempDao.InsertCATempOrgBatch(tempid, lstorg);
			if(result<(itemids.split(",").length+lstorg.size()+1)){
				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
				return -1;
			}
			return result;
		}
		catch(Exception ex){
			ex.printStackTrace();
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
			return -1;
		}
	}
	
	public List<CivilAssTempEntity> GetCAItemByWhere(String where)throws Exception{
		try{
			return civilAssTempDao.GetCAItemByWhere(where);
		}
		catch(Exception ex){
			ex.printStackTrace();
		    return null;
		}
	}
	 public List<CATempDetailEntity> GetItemListByTempId(Long tempid)throws Exception{
		 try{
				return civilAssTempDao.GetItemListByTempId(tempid);
			}
			catch(Exception ex){
				ex.printStackTrace();
			    return null;
			}
	 }
	 public List<Map> GetTempOrgListByTempId(Long tempid,String columns)throws Exception{
		 try{
				return civilAssTempDao.GetTempOrgListByTempId(tempid,columns);
			}
			catch(Exception ex){
				ex.printStackTrace();
			    return null;
			}
	 }
}
